package com.pkk.penguin.frame.know.shiro.shirodemo.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description:注解的统一处理类
 * @author: peikunkun
 * @create: 2018-08-22 17:59
 **/
@ControllerAdvice
@ResponseBody
@Slf4j
public class ShiroExceptionHandler {

  /**
   * @Description: 所有的异常类处理
   * @Param: [request, shiroBusinessException]
   * @return: com.pkk.baseutil.response.CommonResponse<com.pkk.basecommon.vo.impl.ErrorStackTraceRespData>
   * @Author: peikunkun
   * @Date: 2018/8/23 0023 上午 10:39
   */
  /*@ExceptionHandler(value = Exception.class)
  public CommonResponse<ErrorStackTraceRespData> shiroAllExceptionHandle(HttpServletRequest request,
      Exception exception) {
    final ErrorStackTraceRespData errorStackTraceRespData = new ErrorStackTraceRespData();
    errorStackTraceRespData.setClassStr(exception.getClass().toString());
    errorStackTraceRespData.setClassName(exception.getClass().getSimpleName());
    errorStackTraceRespData.setClassSimpleName(exception.getStackTrace()[0].getClass().getSimpleName());
    errorStackTraceRespData.setErrorLine(String.valueOf(exception.getStackTrace()[0].getLineNumber()));
    errorStackTraceRespData.setFileName(exception.getStackTrace()[0].getFileName());
    errorStackTraceRespData.setMethodName(exception.getStackTrace()[0].getMethodName());
    errorStackTraceRespData.setCode(ShiroCode.SYS_EXCEPTION.getCode());
    log.error("出现异常：<br/>" + errorStackTraceRespData.toString());
    return ResponseUtil.exception(errorStackTraceRespData);
  }*/

  /**
   * @Description: 异常处理类
   * @Param: [request, shiroBusinessException]
   * @return: com.pkk.baseutil.response.CommonResponse<com.pkk.basecommon.vo.impl.ErrorStackTraceRespData>
   * @Author: peikunkun
   * @Date: 2018/8/23 0023 上午 10:38
   */
  /*@ExceptionHandler(value = ShiroBusinessException.class)
  public CommonResponse<ErrorStackTraceRespData> shiroExceptionHandle(HttpServletRequest
      request, ShiroBusinessException shiroBusinessException) {
    final ErrorStackTraceRespData errorStackTraceRespData = new ErrorStackTraceRespData();
    errorStackTraceRespData.setClassStr(shiroBusinessException.getClass().toString());
    errorStackTraceRespData.setClassName(shiroBusinessException.getClass().getSimpleName());
    errorStackTraceRespData.setClassSimpleName(shiroBusinessException.getStackTrace()[0].getClass().getSimpleName());
    errorStackTraceRespData.setErrorLine(String.valueOf(shiroBusinessException.getStackTrace()[0].getLineNumber()));
    errorStackTraceRespData.setFileName(shiroBusinessException.getStackTrace()[0].getFileName());
    errorStackTraceRespData.setMethodName(shiroBusinessException.getStackTrace()[0].getMethodName());
    errorStackTraceRespData.setCode(ShiroCode.SYS_EXCEPTION.getCode());
    log.error("出现异常：<br/>" + errorStackTraceRespData.toString());
    return ResponseUtil.exception(errorStackTraceRespData);
  }*/

}
